package com.goodflower.goodflower.chang_user;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.goodflower.goodflower.MainActivity;
import com.goodflower.goodflower.R;
import com.goodflower.goodflower.info.Info;
import com.goodflower.goodflower.util.HttpUtil;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class Change_user_password_ok extends AppCompatActivity {
    private Button btn_change_user_password_one_ok_next;
    private EditText change_user_password_new;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.change_user_password_ok);
        //找到控件
        btn_change_user_password_one_ok_next = (Button) findViewById(R.id.btn_change_user_password_one_ok_next);
        change_user_password_new = (EditText) findViewById(R.id.change_user_password_new);
        //按钮点击事件
        btn_change_user_password_one_ok_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //判断一下用户有没有输入新的密码
                String newpassword = change_user_password_new.getText().toString();
                if (newpassword == null || newpassword.isEmpty()){
                    Toast.makeText(Change_user_password_ok.this,"请输入您的新密码",Toast.LENGTH_LONG).show();
                }else {
                    HttpUtil.sendOkHttpRequest("http://"+Info.server_ip+"/huahua/phone_changepassword.php?username="+ Info.current_user_name+"&password="+newpassword, new Callback() {
                        @Override
                        public void onFailure(Call call, IOException e) {

                        }

                        @Override
                        public void onResponse(Call call, Response response) throws IOException {

                        }
                    });
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(Change_user_password_ok.this,"密码修改成功请重新登录",Toast.LENGTH_LONG).show();
                        }
                    });
                    startActivity(new Intent(Change_user_password_ok.this, MainActivity.class));

                }
            }
        });
    }
}
